#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time: 2025-07-26 22:03
@Author: Fallyn Snow 
@File: basics_of_future.py
"""
import asyncio
from asyncio import Future


async def main():
    # await method_01()
    my_future = Future()
    print(f"我的future完成了吗? {my_future.done()}")
    try:
        print(f"set_result之前访问future的result? {my_future.result()}")
    except asyncio.exceptions.InvalidStateError as ise:
        print(ise)


async def method_01():
    my_future = Future()
    print(f"我的future完成了吗? {my_future.done()}")
    # 设置 future 的结果, 设置之后, 我们认为future是complete的
    my_future.set_result(42)
    print(f"set_result之后, 我的future完成了吗? {my_future.done()}")
    print(f"my_future的result是? {my_future.result()}")


if __name__ == '__main__':
    asyncio.run(main())
